home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / Event / Notification.php < prev   
Encoding:
PHP Script  |  2005-12-02  |  6.2 KB  |  194 lines

  1. <?php
  2. // +-----------------------------------------------------------------------+
  3. // | Copyright (c) 2005, Bertrand Mansion                                  |
  4. // | All rights reserved.                                                  |
  5. // |                                                                       |
  6. // | Redistribution and use in source and binary forms, with or without    |
  7. // | modification, are permitted provided that the following conditions    |
  8. // | are met:                                                              |
  9. // |                                                                       |
  10. // | o Redistributions of source code must retain the above copyright      |
  11. // |   notice, this list of conditions and the following disclaimer.       |
  12. // | o Redistributions in binary form must reproduce the above copyright   |
  13. // |   notice, this list of conditions and the following disclaimer in the |
  14. // |   documentation and/or other materials provided with the distribution.|
  15. // | o The names of the authors may not be used to endorse or promote      |
  16. // |   products derived from this software without specific prior written  |
  17. // |   permission.                                                         |
  18. // |                                                                       |
  19. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
  20. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
  21. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
  22. // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
  23. // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  24. // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
  25. // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  26. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  27. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
  28. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  29. // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
  30. // |                                                                       |
  31. // +-----------------------------------------------------------------------+
  32. // | Author: Bertrand Mansion <bmansion@mamasam.com>                       |
  33. // |         Stephan Schmidt <schst@php.net>                               |
  34. // +-----------------------------------------------------------------------+
  35. //
  36. // $Id: Notification.php,v 1.2 2005/02/14 10:35:18 mansion Exp $
  37.  
  38. /**
  39.  * Default state of the notification
  40.  */
  41. define('EVENT_NOTIFICATION_STATE_DEFAULT', 0);
  42.  
  43. /**
  44.  * Notification has been cancelled
  45.  */
  46. define('EVENT_NOTIFICATION_STATE_CANCELLED', 1);
  47.  
  48. /**
  49.  * A Notification object
  50.  *
  51.  * The Notification object can be easily subclassed and serves as a container
  52.  * for the information about the notification. It holds an object which is 
  53.  * usually a reference to the object that posted the notification,
  54.  * a notification name used to identify the notification and some user
  55.  * information which can be anything you need.
  56.  * 
  57.  * @category   Event
  58.  * @package    Event_Dispatcher
  59.  * @author     Bertrand Mansion <bmansion@mamasam.com>
  60.  * @author     Stephan Schmidt <schst@php.net>
  61.  * @copyright  1997-2005 The PHP Group
  62.  * @license    http://www.opensource.org/licenses/bsd-license.php BSD License
  63.  * @version    Release: 1.0.0
  64.  * @link       http://pear.php.net/package/Event_Dispatcher
  65.  */
  66. class Event_Notification
  67. {
  68.     /**
  69.      * name of the notofication
  70.      * @var string
  71.      * @access private
  72.      */
  73.     var $_notificationName;
  74.     
  75.     /**
  76.      * object of interesed (the sender of the notification, in most cases)
  77.      * @var object
  78.      * @access private
  79.      */
  80.     var $_notificationObject;
  81.     
  82.     /**
  83.      * additional information about the notification
  84.      * @var mixed
  85.      * @access private
  86.      */
  87.     var $_notificationInfo = array();
  88.  
  89.     /**
  90.      * state of the notification
  91.      *
  92.      * This may be:
  93.      * - EVENT_NOTIFICATION_STATE_DEFAULT
  94.      * - EVENT_NOTIFICATION_STATE_CANCELLED
  95.      *
  96.      * @var integer
  97.      * @access private
  98.      */
  99.     var $_notificationState = EVENT_NOTIFICATION_STATE_DEFAULT;
  100.     
  101.     /**
  102.      * amount of observers that received this notification
  103.      * @var mixed
  104.      * @access private
  105.      */
  106.     var $_notificationCount = 0;
  107.  
  108.     /**
  109.      * Constructor
  110.      *
  111.      * @access  public
  112.      * @param   object      The object of interest for the notification,
  113.      *                      usually is the posting object
  114.      * @param   string      Notification name
  115.      * @param   array       Free information array
  116.      */
  117.     function Event_Notification(&$object, $name, $info = array())
  118.     {
  119.         $this->_notificationObject =& $object;
  120.         $this->_notificationName   = $name;
  121.         $this->_notificationInfo   = $info;
  122.     }
  123.  
  124.     /**
  125.      * Returns the notification name
  126.      * @return  string Notification name
  127.      */
  128.     function getNotificationName()
  129.     {
  130.         return $this->_notificationName;
  131.     }
  132.  
  133.     /**
  134.      * Returns the contained object
  135.      * @return  object Contained object
  136.      */
  137.     function &getNotificationObject()
  138.     {
  139.         return $this->_notificationObject;
  140.     }
  141.  
  142.     /**
  143.      * Returns the user info array
  144.      * @return  array user info
  145.      */
  146.     function getNotificationInfo()
  147.     {
  148.         return $this->_notificationInfo;    
  149.     }
  150.  
  151.    /**
  152.     * Increase the internal count
  153.     *
  154.     * @access   public
  155.     */
  156.     function increaseNotificationCount()
  157.     {
  158.         ++$this->_notificationCount;
  159.     }
  160.     
  161.    /**
  162.     * Get the number of posted notifications
  163.     *
  164.     * @access   public
  165.     * @return   int
  166.     */
  167.     function getNotificationCount()
  168.     {
  169.         return $this->_notificationCount;
  170.     }
  171.     
  172.    /**
  173.     * Cancel the notification
  174.     *
  175.     * @access   public
  176.     * @return   void
  177.     */
  178.     function cancelNotification()
  179.     {
  180.         $this->_notificationState = EVENT_NOTIFICATION_STATE_CANCELLED;
  181.     }
  182.  
  183.    /**
  184.     * Checks whether the notification has been cancelled
  185.     *
  186.     * @access   public
  187.     * @return   boolean
  188.     */
  189.     function isNotificationCancelled()
  190.     {
  191.         return ($this->_notificationState === EVENT_NOTIFICATION_STATE_CANCELLED);
  192.     }
  193. }
  194. ?>